﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace RestEntities
{
	[DataContract]
	public class Person
	{
		public Person()
		{
			Comments = new List<Comment>();
			Id = Person.GetNextPersonId();
		}

		public Person(Guid id)
		{
			Comments = new List<Comment>();
			Id = id;
		}

		[DataMember(Order = 1)]
		public Guid Id { get; set; }

		[DataMember(Order = 2)]
		public string Name { get; set; }

		[DataMember(Order = 3)]
		public string LastName { get; set; }

		[DataMember]
		public List<Comment> Comments
		{
			get;
			set;
		}

		[DataMember(Order = 4)]
		public Uri Uri
		{
			get;
			set;
		}

		public static Guid GetNextPersonId()
		{
			return Guid.NewGuid();
		}

		public void Update(Person person)
		{
			if (person == null)
			{
				return;
			}

			Name = person.Name;
			LastName = person.LastName;
			Uri = person.Uri;

			if (person.Comments == null)
				person.Comments = new List<Comment>();

			this.Comments = person.Comments;
		}
	}

	[DataContract]
	public class Comment
	{
		public Comment()
		{
			CommentId = Guid.NewGuid();
			Time = DateTime.Now;
		}

		public Comment(DateTime time)
		{
			CommentId = Guid.NewGuid();
			Time = time;
		}

		[DataMember(Order = 3)]
		public string CommentHead
		{
			get;
			set;
		}

		[DataMember(Order = 4)]
		public string CommentBody
		{
			get;
			set;
		}

		[DataMember(Order = 1)]
		public Guid CommentId
		{
			get;
			set;
		}

		[DataMember(Order = 5)]
		public DateTime Time
		{
			get;
			set;
		}

		[DataMember]
		public Uri Uri
		{
			get;
			set;
		}

		public void Update(Comment comment)
		{
			if (comment == null)
			{
				return;
			}

			CommentHead = comment.CommentHead;
			CommentBody = comment.CommentBody;
			Time = comment.Time;
			Uri = comment.Uri;
		}
	}
}
